package com.yutianran.springBoot.spider.impl;

import com.yutianran.springBoot.spider.IParser;
import com.yutianran.springBoot.spider.Node;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class CsdnParser implements IParser {

    public List<Node> parse(Document document) throws IOException {
        List<Node> list = new LinkedList<Node>();
        Elements itemList = document.select("ul.detail_list").first().select("li");
        for (Element element : itemList) {
            Element a = element.select("h4").first().select("a").first();
            String name = a.text();
            String link = a.attr("href");
            list.add(new Node(name, link));
        }
        return list;
    }
}
